import baseUrl from "../config.js"
import {
	addError
} from '../api/system.js'
let request = (url, method = 'GET', data = {}, dataType = "json", header = {}) => {
	if (uni.getStorageSync('TOKEN') && (url.indexOf('http://') == -1 && url.indexOf('https://') == -1)) {
		header.Authorization = 'Bearer ' + uni.getStorageSync('TOKEN')
	}
	return new Promise((resolve, reject) => {
		uni.request({
			url: (url.indexOf('http://') > -1 || url.indexOf('https://') > -1 ? url : baseUrl +
				url),
			method: method,
			data: data,
			dataType: dataType,
			header: header,
			success(res) {
				if (res.statusCode === 200 || res.statusCode === 201) {
					resolve(res.data)
				} else {
					reject(res)
					uni.hideLoading()
				}
			},
			fail(res) {
				reject(res)
				uni.hideLoading()
			}
		})
	})
}
export default request
